<template>
	<view>
		<view class="cart-header">
			<uni-search-bar class="cart-search" radius="40" placeholder="运单号,寄件或收件人姓名(电话)" cancelButton="none"
				bgColor="#f5f5f5" v-model="order_no" @confirm="getDateList()" />
			<view class="tabs">
				<uni-segmented-control :current="current" :values="items" style-type="text" active-color="#0396ff"
					@clickItem="clickItem()" />
			</view>
		</view>
		<view class="cart-content">
			<view class="tip-box">
				超重部分需要补缴运费，请知晓，谢谢！
			</view>
			<view class="cart-list">
				<view v-for="item in list" :key="item.id" class="card cart-box">
					<view class="head-box">
						<view class="brand">
							{{ item.channelSubTag }}
						</view>
						<view class="order" v-if="item.waybill">
							运单号：<text class="number">{{ item.waybill }}</text>
						</view>
						<view  v-if="item.waybill" @tap.stop="copy" :data-text="item.waybill" class="copy">
							复制
						</view>
						<view class="order" v-else>{{item.nowaybill}}</view>
					</view>
					<view class="info-box">
						<view class="sending">
							<view class="from-to">
								<view class="area">
									{{ item.senderCity }}
								</view>
								<view class="name">
									{{ item.sender }}
								</view>
							</view>
							<view class="status">
								<view class="text">
									{{ items[(item.status=='0'?4:item.status)] }}
								</view>
								<image class="right" src="https://wuliu.suchenqiang.cn/static/index/img/right.png"></image>
							</view>
							<view class="from-to">
								<view class="area">
									{{ item.receiveProvince }}
								</view>
								<view class="name">
									{{ item.receiver }}
								</view>
							</view>
						</view>
						<view class="list">
							<view class="list-item">
								系统单号：{{ item.shopbill }} <text @tap.stop="copy" :data-text="item.shopbill">复制</text>
							</view>
							<view class="list-item">
								下单时间：{{ item.createTime }}
							</view>
							<view class="list-item" v-if="item.courierName">
								快递员姓名：{{item.courierName}}，电话：{{item.courierPhone}} <text @click="callphone(item.courierPhone)" class="cicon-phone-call"></text>
							</view> 
						</view>
					</view>
					<view class="foot-box">
						<view class="button" v-show="item.status == 1" @tap="onCancel(1,item.waybill)">
							取消订单
						</view>
						<view class="button bg-blue" @tap="goto" :data-url="'/kuaidi/order/detail?id='+item.id">
							查看详情
						</view>
						<view class="button" v-show="item.status == 4" @tap="onCancel(2,item.waybill)">
							删除订单
						</view>
					</view>
				</view>
			</view>
		</view>
		<dp-tabbar :opt="opt"></dp-tabbar>
		
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				opt:{},
				items: ['全部', '待取件', '运输中', '已完成', '已取消'],
				current:'all',
				list:[],
				page:1,
				limit:10,
				total:10,
				is_show:false
			};
		},
		onLoad: function() {
			this.getDateList();
		},
		onReachBottom() {
			if (this.page * this.limit >= this.total) return
			if (this.isloading) return
			// 让页码值自增+1
			this.page++
			this.getDateList()
		},
		onShow() {
			if(this.is_show){
				this.clickItem();
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.list = [];
			this.getDateList(() => uni.stopPullDownRefresh())
		},
		methods: {
			callphone(telmobild) {
				let that = this;
				uni.makePhoneCall({
					phoneNumber: telmobild //仅为示例
				});
			},
			onCancel(type,waybill){
				let that = this;
				app.confirm('确定'+(type==1?'取消':'删除')+'订单?', function() {
					app.post('ApiKuaidi/'+(type==1?'kuaidieCelOrder':'kuaidiDelOrder'), {
						waybill:waybill,
					}, function(res) {
						if(res.code==1){
							app.success(res.msg);
							that.clickItem();
						}else{
							app.error(res.msg);
						}
					});
				});
			},
			clickItem(){
				this.page = 1;
				this.list = [];
				this.getDateList()
			},
			getDateList(cb) {
				let that = this;
				app.post('ApiKuaidi/selectOrder', {
					page:that.page,
					limit:that.limit,
					order_no:that.order_no,
					status:(that.current?that.current:'all')
				}, function(res) {
					cb && cb();
					app.showLoading(false);
					that.loading = false;
					that.is_show = true;
					if (res.code == 0) {
						that.list.push(...res.data);
						that.total = res.count;
					}
					that.loaded();
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.cart-header {
		background-color: #fff;
		padding: 30rpx 20rpx 4rpx;

		.cart-search {
			margin-bottom: 20rpx;

			:deep(.uni-searchbar__box) {
				height: 80rpx;
			}
		}
	}

	.cart-content {
		padding: 20rpx;

		.tip-box {
			height: 80rpx;
			line-height: 80rpx;
			border-radius: 20rpx;
			background-color: #fef5e4;
			border: 2rpx solid #ece6ae;
			color: #dfab6e;
			text-align: center;
			font-size: 24rpx;
		}
	}

	.cart-box {
		margin-top: 20rpx;

		.head-box {
			display: flex;
			align-items: center;
			padding: 20rpx;
			font-size: 30rpx;
			column-gap: 20rpx;
			border-bottom: 2rpx solid #eeeeee;

			.brand {
				width: 120rpx;
				height: 68rpx;
				line-height: 68rpx;
				border-radius: 34rpx;
				background-color: #ea883f;
				text-align: center;
				color: #fff;
			}

			.order {
				color: #2c2c2c;

				.number {
					color: #ff6600;
				}
			}

			.copy {
				color: #999999;
				font-size: 24rpx;
			}
		}

		.info-box {
			display: flex;
			flex-direction: column;
			row-gap: 40rpx;
			padding: 10rpx 30rpx;
			border-bottom: 2rpx solid #eeeeee;

			.sending {
				display: flex;
				justify-content: space-around;
				align-items: center;
				margin-top: 20rpx;

				.from-to {
					display: flex;
					flex-direction: column;
					align-items: center;
					row-gap: 12rpx;

					.area {
						font-size: 36rpx;
						color: #2c2c2c;
						font-weight: 600;
					}

					.name {
						color: #999999;
					}
				}

				.status {
					display: flex;
					flex-direction: column;
					align-items: center;

					.text {
						color: #0396ff;
						font-size: 32rpx;
					}

					.right {
						width: 120rpx;
						height: 80rpx;
					}
				}
			}

			.list {
				&-item {
					padding: 10rpx 0;
					color: #999999;
				}
			}
		}

		.foot-box {
			display: flex;
			justify-content: flex-end;
			column-gap: 20rpx;
			padding: 20rpx;

			.button {
				width: 180rpx;
				height: 68rpx;
				line-height: 68rpx;
				text-align: center;
				color: #000000;
				background-color: #f5f5f5;
				font-size: 30rpx;
				border-radius: 34rpx;

				&.bg-blue {
					background-color: #0396ff;
					color: #fff;
				}
			}
		}
	}
	.cart-box.data-v-c30a4c2b {
	    margin-top: 20rpx;
	}
	.card {
	    border-radius: 20rpx;
	    background-color: #fff;
	}
</style>